///////////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008  
// Authors: Aljosa Osep (aljosa.osep@gmail.com), Jernej Kranjec (jernej.kranjec@gmail.com)
// From Faculty of Electrical Engineering and Computer Science, Maribor, Slovenia
// Done at School of Technology, Seinajoki, Finland
// Under mentor Kimmo Salmenjoki (kimmo.salmenjoki@seamk.fi)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////////////////
//
// connection.cs created with MonoDevelop
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;
using System.IO;

namespace simpleServer
{
	public partial class connection : Gtk.Dialog
	{
		private int port;
		MainWindow globalMainWindowPtr;
		
		public connection(MainWindow mainWindowPtr)
		{
			this.Build();
			globalMainWindowPtr = mainWindowPtr;
			mainWindowPtr.readConnectionSettings(ref port);
			entryPort.Text = port.ToString();
		}
		
		public void saveConfiguration()
		{
			if (entryPort.Text == "")
            {
                // error msg
            }
            else
            {
                StreamWriter write_config; // stream for writing file
                try
                {
                    // file exsists, write new settings
                    File.Delete("server_config.cfg"); //File.OpenWrite("client_config.cfg");
                    write_config = File.CreateText("server_config.cfg");
                    write_config.WriteLine(entryPort.Text);
                    write_config.Close();
                }
                catch (FileNotFoundException)  // file doesn't exist yet
                {
                    write_config = File.CreateText("client_config.cfg");
                    write_config.WriteLine(entryPort.Text);
                    write_config.Close();
                }
            }
			
			port = System.Convert.ToInt16(entryPort.Text);
			globalMainWindowPtr.port = port;

        }
	}
}
